#pragma once

#include <vfw.h>

class CSprScr : public CWnd
{
		DECLARE_DYNAMIC(CSprScr)
		static const DWORD  m_pColorPalettes[16][4];
		static const DWORD  m_pMonochromePalette[2][4];
		static const DWORD  m_pAdaptMonochromePalette[2][4];

		BYTE    *m_pBuffer;
		size_t  m_nBufSize;

		int     m_PaletteNum;
		int     m_nScale;
		int     m_cx, m_cy;
		int     m_orig_cx, m_orig_cy;

		BOOL    m_bColorMode;
		BOOL    m_bAdapt;
		BOOL    m_bBusy;
		BOOL    m_bChangeMode;

		DWORD   *m_pColTable32;
		DWORD   *m_pMonoTable32;
		DWORD   *m_bits;

		HWND    m_hwndScreen;  // Screen View window handle
		HDRAWDIB m_hdd;
		HBITMAP m_hbmp;
		BITMAPINFO m_bmpinfo;

	public:
		CSprScr();
		virtual ~CSprScr(void);
		void DrawScreen();
		void ReDrawScreen();
		void AdjustLayout(int cx, int cy, int ysp);

		void SetParameters(BYTE *buffer, size_t size, int scale)
		{
			m_pBuffer = buffer; m_nBufSize = size; SetScale(scale);
		}

		inline const size_t GetBufferSize()
		{
			return m_nBufSize;
		}

		void SetScale(int scale);

		inline const int GetScale()
		{
			return m_nScale;
		}

		void SetPalette(int palette);

		inline const int GetPalette()
		{
			return m_PaletteNum;
		}

		void SetAdaptMode(BOOL bFlag);

		inline const BOOL IsAdaptMode()
		{
			return m_bAdapt;
		}

		void SetColorMode(BOOL bColorMode = TRUE);

		inline const BOOL IsColorMode()
		{
			return m_bColorMode;
		}

	protected:
		void ScreenView_Init();
		void ScreenView_Done();
		void InitColorTables();
		void PrepareScreenRGB32();
		void CalcOrigSize();
		virtual BOOL PreCreateWindow(CREATESTRUCT &cs);
		afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
		afx_msg void OnDestroy();
		afx_msg BOOL OnEraseBkgnd(CDC *pDC);
		DECLARE_MESSAGE_MAP()
};

